﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace eDream.Page
{
    public partial class Introduced_myself : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                for (int i = 2010; i >= 1950; i--)
                {
                    cbNam.Items.Add(i.ToString(), i);
                }

                try
                {
                    UserDB user_obj = (UserDB)Session[Global.SESS_USER];
                    txtCMND.Text = user_obj.cmnd;
                    txtDiachi.Text = user_obj.address;
                    txtDienthoai.Text = user_obj.phone;
                    txtEmail.Text = user_obj.email;
                    txtFirstname.Text = user_obj.FirtName;
                    txtLassname.Text = user_obj.Lastname;
                    txtNguoigioithieu.Text = user_obj.nguoigioithieu;
                    txtUserName.Text = user_obj.UserName;
                    cbGioitinh.Value = user_obj.gioitinh;
                    cbNam.Value = user_obj.namsinh;
                    cbThang.Value = user_obj.thangsinh;
                    cbNgay.Value = user_obj.ngaysinh;
                    txtVisa.Text = user_obj.visa;
                }
                catch (Exception) { }

            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (txtUserName.Text != "" && txtLassname.Text != ""
                   && txtFirstname.Text != "" && txtDienthoai.Text != "" && txtEmail.Text != "" && txtDiachi.Text != "" && txtCMND.Text != "")
            {
                UserDB user_obj = (UserDB)Session[Global.SESS_USER];
                DataClasses1DataContext dx = new DataClasses1DataContext();
                try
                {
                    dx.Connection.Open();
                    dx.sp_updateIntroduceMyself(user_obj.ID, txtFirstname.Text.Trim(), txtLassname.Text.Trim(), txtEmail.Text.Trim(), txtDienthoai.Text.Trim(), txtDiachi.Text.Trim(), cbGioitinh.Text, int.Parse(cbNgay.Text), int.Parse(cbNam.Text), int.Parse(cbThang.Text), txtCMND.Text, txtVisa.Text);
                    dx.SubmitChanges();

                    lbthongbao.ForeColor = Color.Blue;
                    lbthongbao.Text = "Thông tin của bạn đã được cập nhật";
                }
                catch (Exception)
                {
                    lbthongbao.ForeColor = Color.Red;
                    lbthongbao.Text = "Đã xảy ra lỗi trong quá trình xử lý";
                }
                finally { dx.Connection.Close(); }
            }
        }
    }
}